package com.web.music.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.web.music.interfaces.PersistenceHelper;
import com.web.music.interfaces.GenreService;
import com.web.music.model.PersistentEntity;
import com.web.music.model.Genre;

@Transactional
public class GenreServiceImpl implements GenreService {
	
	private PersistenceHelper persistence;
	
	public void save(Genre genre) {
		persistence.save(genre);
	}

	public List<Genre> findAll() {
		List<PersistentEntity> all = persistence.findAll(Genre.class);
		List<Genre> genres = new ArrayList<Genre>(); 
		for (PersistentEntity e: all){
			genres.add((Genre)e);
		}
		return genres; 
	}
	
	public Genre getById(Long id) {
		return (Genre)persistence.getById(Genre.class, id);
	}

	public PersistenceHelper getPersistence() {
		return persistence;
	}

	public void setPersistence(PersistenceHelper persistence) {
		this.persistence = persistence;
	}
}